
<template>
  <div>
    <van-cell icon="arrow-left" title="管理员" is-link to="/" size="large" :value="user"/>
    <van-tabs>
      <van-tab title="医院管理">
        <hospitals></hospitals>
      </van-tab>
      <van-tab title="用户管理">
        <users></users>
      </van-tab>
    </van-tabs>
    <van-dialog v-model="showLogin" title="登录/注册" :lazy-render="false" 
      :showConfirmButton="false" show-cancel-button @cancel="onCancel">
        <login @onLogin="onLogin" />
    </van-dialog>
  </div>
</template>

<script>
  import { get } from "@/api/common";
  import Hospitals from "./hospitals";
  import Login from "../components/Login";
  import Users from "./users";
  import { Toast } from 'vant';

  export default {
    components: {
      Hospitals,
      Users,
      Login,
    },
    computed:{
      user () {
        if(this.$store.state.loginId=='zyz')
          return '';
        else
          return this.$store.state.loginId;
      }
    },
    data() {
      return {
        showLogin : true,
      }
    },
    mounted() {
      if(this.$store.state.userId>0) {
        this.showLogin = true;
      }
    },
    methods: {
      // 登录后
      onLogin(value) {
        if(this.$store.state.userRole=='管理人员')
          this.showLogin = false;
        else
          Toast('必须是[管理人员]角色的用户才可以进入');
      },
      onCancel() {
        this.$router.push({path:'/'});
      }
    }
  }
</script>

<style scoped>

</style>
  